let exp = module.exports;
let enumeration = require('../constant/enumeration');
let logger = require('pomelo-logger').getLogger('logic');

let gameList = [{
    gameType: enumeration.gameType.NN,
    gameFrameSinkPath: 'niuniu/gameFrame',
    maxPlayerCount: 10
}];

//新框架获取
exp.getGameFrameByType = function (type) {

    if ([enumeration.gameType.PDK].includes(type)) {
        return {
            gameType: enumeration.gameType.PDK,
            gameFrameSinkPath: 'paodekuai/gameFrame',
            maxPlayerCount: 4
        };
    } else if ([enumeration.gameType.FJSSS, enumeration.gameType.JDSSS, enumeration.gameType.CSSSS, enumeration.gameType.BBSSS].includes(type)) {
        return {
            gameType: enumeration.gameType.FJSSS,
            gameFrameSinkPath: 'fjsss/gameFrame',
            maxPlayerCount: 8
        };
    }
    return null;
}


//判断是否人满开局
exp.isFullStart = function (gameType) {

    let fullStartList = [
        enumeration.gameType.PDK,
        enumeration.gameType.NN,
        enumeration.gameType.JDSSS,
        enumeration.gameType.CSSSS,
        enumeration.gameType.BBSSS,
        enumeration.gameType.FJSSS,
    ]
    return fullStartList.includes(gameType);

}


exp.getDefaultMaxPlayerCount = function (gameType) {
    for (let i = 0; i < gameList.length; ++i) {
        if (gameType === gameList[i].gameType) {
            return gameList[i].maxPlayerCount;
        }
    }
    throw new Error('getDefaultMaxPlayerCount，游戏类型错误gameType=' + gameType);
};

exp.getGameFrameSink = function (gameType) {
    for (let i = 0; i < gameList.length; ++i) {
        if (gameType === gameList[i].gameType) {
            return gameList[i].gameFrameSinkPath;
        }
    }
    throw new Error('getGameFrameSink，游戏类型错误gameType=' + gameType);
};

let diamondConfig = {};

diamondConfig[enumeration.gameType.NN] = {
    10: 10,
    20: 20,
    30: 30
};

diamondConfig[enumeration.gameType.PDK] = {
    8: 8,
    12: 12,
    16: 16
};

diamondConfig[enumeration.gameType.FJSSS] = {
    10: 10,
    20: 20,
    30: 30
};

diamondConfig[enumeration.gameType.JDSSS] = {
    10: 10,
    20: 20,
    30: 30
};

diamondConfig[enumeration.gameType.CSSSS] = {
    10: 10,
    20: 20,
    30: 30
};

diamondConfig[enumeration.gameType.BBSSS] = {
    10: 10,
    20: 20,
    30: 30
};



exp.oneUserDiamondCount = function (bureau = 0, gameType, chairCount = 2) {
    try {

        let count = diamondConfig[gameType] && diamondConfig[gameType][bureau] || 1;
        return count * chairCount;
    } catch (e) {
        logger.error(e.stack);
        logger.error("oneUserDiamondCount err: bureau=" + bureau + ",gameType=" + gameType);
        return 1;
    }
};